package com.lemon.core.conf.jmx;


import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class NamedThreadFactory implements ThreadFactory {

    protected final String id;

    private final AtomicInteger n = new AtomicInteger(1);

    NamedThreadFactory(String id) {
        this.id = id;
    }


    public Thread newThread(Runnable runnable) {
        String name = id + ":" + n.getAndIncrement();
        return new Thread(runnable, name);
    }

    public String getId() {
        return id;
    }
}
